package com.v2future.sjt.collegecheckingattendance.fruit.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.TextView;

import com.v2future.sjt.collegecheckingattendance.R;
import com.v2future.sjt.collegecheckingattendance.event.adapter.EventImgGridAdapter;
import com.v2future.sjt.collegecheckingattendance.fruit.bean.ConditionBean;
import com.v2future.sjt.collegecheckingattendance.fruit.bean.ConditionTypeBean;
import com.v2future.sjt.collegecheckingattendance.utils.WidgetUtil;

import java.util.List;

/**
 * Created by Administrator on 2016/1/25.
 */
public class FruitAdapter extends BaseAdapter{

    List<ConditionBean> dataList;
    Context mContext;
    ConditionTypeBean conditionTypeBean;//成长类型

    public FruitAdapter(List<ConditionBean> dataList, Context mContext) {
        this.dataList = dataList;
        this.mContext = mContext;
    }

    @Override
    public int getCount() {
        return dataList.size();
    }

    @Override
    public Object getItem(int position) {
        return dataList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    public ConditionTypeBean getConditionTypeBean() {
        return conditionTypeBean;
    }

    public void setConditionTypeBean(ConditionTypeBean conditionTypeBean) {
        this.conditionTypeBean = conditionTypeBean;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        ConditionBean bean = dataList.get(position);
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(
                    R.layout.listitem_grow, null);
            holder = new ViewHolder();
            holder.titleTv = (TextView) convertView.findViewById(R.id.tv_grow_title);
            holder.timeTv = (TextView) convertView.findViewById(R.id.tv_time);
            holder.addrTv = (TextView) convertView.findViewById(R.id.tv_addr);
            holder.contentTv = (TextView) convertView.findViewById(R.id.tv_content);
            holder.imagesGv = (GridView) convertView.findViewById(R.id.gv_release_images);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        //奖惩
        if("5".equals(conditionTypeBean.getConditonTypeId())) {
            WidgetUtil.setText(holder.contentTv, bean.getConditionDesc());
            WidgetUtil.setText(holder.addrTv, bean.getConditionUnit());
        }
        //科研
        else if ("6".equals(conditionTypeBean.getConditonTypeId())) {
            WidgetUtil.setText(holder.contentTv, bean.getResearchRemark());
            WidgetUtil.setText(holder.addrTv, bean.getResearchDesc());
        }
        else {
            WidgetUtil.setText(holder.contentTv, bean.getConditionDesc());
            WidgetUtil.setText(holder.addrTv, bean.getConditionArea());
        }
        WidgetUtil.setText(holder.timeTv, bean.getConditionDate());
        WidgetUtil.setText(holder.titleTv, bean.getConditionTitle());
        //图片
        if (null != bean.getImageUrl() && bean.getImageUrl().size() > 0) {
            holder.imagesGv.setVisibility(View.VISIBLE);
            EventImgGridAdapter imageUrlAdapter = new EventImgGridAdapter(mContext, bean.getImageUrl());
            holder.imagesGv.setAdapter(imageUrlAdapter);
        }
        else {
            holder.imagesGv.setVisibility(View.GONE);
        }
        return convertView;
    }

    public class ViewHolder {
        TextView titleTv;
        TextView timeTv;
        TextView addrTv;
        TextView contentTv;
        GridView imagesGv;
    }
}
